package com.rock.platform.core;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.Result;
import com.opensymphony.xwork2.util.ValueStack;
import com.rock.platform.util.ActionJsonResult;

import java.io.PrintWriter;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;

public class JsonStringResult implements Result {
	private static final long serialVersionUID = 4565340493961436575L;

	public void execute(ActionInvocation invocation) throws Exception {
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setContentType("text/plain;charset=utf-8");
		PrintWriter pw = response.getWriter();

		ValueStack vs = invocation.getStack();

		Object jsonString = vs.findValue("jsonString");
		if ((jsonString != null) && (!(jsonString.equals("")))) {
			pw.print(jsonString.toString());
		} else {
			pw.print(ActionJsonResult.getSuccessResult());
		}
	}
}